// ////////////////////////////////////////////////////////////////////////////////////////
// NAME: GenericActivity.java 
// AUTHOR: CDT Riley Mckenna 
// LAST MODIFIED: 28 March 2012 
// DESCRIPTION: Contains code for Tabs and General UI.
// LIMITATIONS: 
// CITATIONS: In code
// 
// ////////////////////////////////////////////////////////////////////////////////////////
package prototype.revision;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

public class GenericActivity extends Activity {
	private Toast t;
	private Activity activity = this;
	private FileOperations fo = new FileOperations(activity);

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}

	public FileOperations getFileOp() {
		return fo;
	}

	public void setActivity(Activity act) {
		activity = act;
	}

	@Override
	public void onPause() {
		super.onPause();
	}

	@Override
	public void onStop() {
		super.onStop();
	}

	@Override
	public void onResume() {
		super.onResume();
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.about:
			checkClass();
			break;
		case R.id.settings:
			startActivity(new Intent(this, Settings.class));
			break;
		case R.id.log:
			startActivity(new Intent(this, LogView.class));
			break;
		case R.id.exit:
			finish();
			break;
		default:
			break;
		}
		return true;
	}

	public void checkClass() {
		Class<? extends Activity> curClass = super.getClass();
		if (curClass == Home.class) {
			popToast("home");
		} else if (curClass == ListViewActivity.class) {
			popToast("firewall");
		} else if (curClass == AboutActivity.class) {
			popToast("about");
		} else if (curClass == (BatteryScanner.class)) {
			popToast("analyzer");
		} else if (curClass == (Settings.class)) {
			popToast("settings");
		} else if (curClass == (ListViewActivity.class)) {
			popToast("viewlog");
		} else {
			popToast("never");
		}
	}

	private CharSequence getMessage(String string) {
		// TODO Auto-generated method stub
		if (string == "home") {
			return "This is the Home Tab" + '\n'
					+ "Select a Tab from the top or press the menu button";
		} else if (string == "firewall") {
			return "This is the " + string + " tab" + '\n'
					+ "Select an application to change its firewall settings";
		} else if (string == "about") {
			return "This is the " + string + " tab";
		} else if (string == "analyzer") {
			return "This is the " + string + " tab" + '\n'
					+ "Select an application to change its firewall settings";
		} else if (string == "settings") {
			return "This is the " + string + " tab" + '\n'
					+ "Adjust the automated features by selecting an option";
		} else if (string == "viewlog") {
			return "This is the "
					+ string
					+ " tab"
					+ '\n'
					+ "View kernal messages to see what programs are secretly up to";
		} else {
			return "Its seems to be an error";
		}
	}
	
	public void statusNotificationBlocker(String title, String app, String status, Activity act){
		String ns = Context.NOTIFICATION_SERVICE;
		NotificationManager mNotificaitonManager = (NotificationManager) act.getSystemService(ns);
		int icon = R.drawable.events_grey_icon;
		CharSequence tickerText = status;
		long when = System.currentTimeMillis();
		Notification notification = new Notification(icon, tickerText, when);
		Context context = act.getApplicationContext();
		CharSequence contentTitle = title;
		CharSequence contentText = "The application " + app + " has been " + status;
		Intent notificationIntent = new Intent(act, ListViewActivity.class);
		PendingIntent contentIntent = PendingIntent.getActivity(act, 0, notificationIntent, 0);
		notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
		mNotificaitonManager.notify(1, notification);
	}
	
	public void statusNotificationClearFile(String title, String body, String ticker, Activity act){
		String ns = Context.NOTIFICATION_SERVICE;
		NotificationManager mNotificaitonManager = (NotificationManager) act.getSystemService(ns);
		int icon = R.drawable.events_grey_icon;
		CharSequence tickerText = ticker;
		long when = System.currentTimeMillis();
		Notification notification = new Notification(icon, tickerText, when);
		Context context = act.getApplicationContext();
		CharSequence contentTitle = title;
		CharSequence contentText = body;
		Intent notificationIntent = new Intent(act, ListViewActivity.class);
		PendingIntent contentIntent = PendingIntent.getActivity(act, 0, notificationIntent, 0);
		notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
		mNotificaitonManager.notify(1, notification);
	}

	private void popToast(String string) {
		// TODO Auto-generated method stub
		t = Toast.makeText(getApplicationContext(), getMessage(string), 15);
		t.show();
	}
	
	public void popToaster(String string) {
		// TODO Auto-generated method stub
		t = Toast.makeText(getApplicationContext(), string, 15);
		t.show();
	}

	public void onStop(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onStop();
	}

	public void onPause(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onPause();
	}

	public void onResume(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onResume();
	}

}
